package com.knightboy.smartshoes.myUi;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.knightboy.smartshoes.R;
import com.knightboy.smartshoes.coreUtil.SenserData;
import com.knightboy.smartshoes.coreUtil.SharedData;
import com.knightboy.smartshoes.coreUtil.UploadLocation;
import com.knightboy.smartshoes.myView.RoundProgressBar;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by knightBoy on 2015/8/3.
 * 进入这个界面的时候，FirstActivity的数据处理功能停止了
 */
public class FootActivity extends Activity {
    private RoundProgressBar roundProgressBar1, roundProgressBar2;
    private Button back_bt;
    private Timer mtimer;
    private TimerTask timerTask;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.foot);
        //初始化
        init();
    }

    @Override
    protected void onResume() {
        super.onResume();

        //定时任务，不断更新压力的数据
        mtimer = new Timer();
        timerTask = new TimerTask() {
            @Override
            public void run() {
                double stress1 = SharedData.getStress1();
                double stress2 = SharedData.getStress2();
                int rate1 = (int)(stress1/10);
                int rate2 = (int)(stress2/10);
                roundProgressBar1.setProgress(rate2);
                roundProgressBar2.setProgress(rate1);

//                String urlStr = "http://1.kbdouni.sinaapp.com/shoes/uploadPre.php?"
//                        +"pressure1=" +SenserData.getPressure1()
//                        +"&pressure2="+ SenserData.getPressure2();
//                new UploadLocation().execute(urlStr);
            }
        };
        mtimer.schedule(timerTask, 0, 500);
    }

    /**
     * 初始化函数
     */
    private void init(){
        //获得控件引用
        roundProgressBar1 = (RoundProgressBar)findViewById(R.id.roundProgressBar1);
        roundProgressBar2 = (RoundProgressBar)findViewById(R.id.roundProgressBar2);
        back_bt = (Button)findViewById(R.id.back_bt);

        back_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                mtimer.cancel();
            }
        });
    }
}
